package com.font {
	import flash.text.Font;
	import flash.utils.Dictionary;

	/**
	 * 过多使用单例，内存使用量大 
	 * @author Lonovo
	 * 
	 */	
	public class FontEmbed{
		private static var _instance:FontEmbed;
		private var fonts:Vector.<Class>;
		private var dictionary:Dictionary;
		
		public function FontEmbed(se:SingletonEnforcer){
			if(!se){
				throw new Error("请使用单例获取方法");
			}
			dictionary = new Dictionary();
		}
		
		public static function getInstance():FontEmbed{
			if(_instance==null){
				_instance = new FontEmbed(new SingletonEnforcer());
			}
			return _instance;
		}
		/**
		 * 设置字体的class与标识名 
		 * @param cla
		 * @param key
		 * 
		 */		
		public function setFontClass(cla:Class,key:String):void{
			Font.registerFont(cla);
			var font:Font = new cla() as Font;
			dictionary[key] = font.fontName;
		}
		/**
		 * 根据标识名返回字体名
		 * @param key
		 * 
		 */		
		public function getFontName(key:String):String{
			return dictionary[key];
		}
	}
}

class SingletonEnforcer{
}
